#include <iostream>
#include <stack>
#include <string>
#include <unordered_map>

bool is_valid_sequence(const std::string& sequence) {
    std::stack<char> stack;
    std::unordered_map<char, char> brackets = {{'(', ')'}, {'[', ']'}, {'{', '}'}, {'<', '>'}};
    for (char bracket : sequence) {
        if (brackets.count(bracket)) {
            stack.push(bracket);
        } else {
            if (stack.empty()) {
                return false;
            }
            char last_opening_bracket = stack.top();
            stack.pop();
            if (brackets[last_opening_bracket] != bracket) {
                return false;
            }
        }
    }
    return stack.empty();
}

int main() {
    std::string sequence;
    std::cout << "Введите скобочную последовательность: ";
    std::cin >> sequence;
    std::cout << std::boolalpha << is_valid_sequence(sequence) << std::endl;
    return 0;
}